#ifndef DEVLIST_DATA_H
#define DEVLIST_DATA_H

#include "custom_ui/treeitem.h"

#define TREE_DATA_TYPE_GROUP				1
#define TREE_DATA_TYPE_DEVICE				2
#define TREE_DATA_TYPE_POLL_GROUP			3
#define TREE_DATA_TYPE_POLL_STORE			4
#define TREE_DATA_TYPE_POLL_DEVICE			5

typedef struct DeviceNode_t
{
	char m_strShowName[256];
	char m_strDeviceSn[128];    // 唯一标识符
	char m_strDeviceId[32];

	int	  m_dwStoreId;
	int   m_dwDevAutoId;
	int   m_dwChannelId;

	int   m_dwUpRate;
	int   m_dwDeviceType;
    int   m_dwViewing;

	bool  m_bCurPlaying;
	bool  m_bPrePlaying;
	bool  m_bOnline;
	bool  m_bVirtual;
}DeviceNode;

typedef struct GroupNode_t
{
	int 	m_dwGroupID;                     // 组ID号  - 唯一标识符
	char 	m_strGroupName[256];             // 组名称
	int 	m_dwParentGroupID;               // 父组ID号
	bool    m_bIsStore;
}GroupNode;

class GroupTreeNode : public TreeItem, public TreeItemData<GroupNode>
{
public:
	explicit GroupTreeNode(GroupNode* pData = nullptr);
	virtual ~GroupTreeNode();

	/// TreeItem
    QVariant data(int role, int column) const override;
    void* Ptr() const override { return GetData(); }
	int DataType() const override { return TREE_DATA_TYPE_GROUP; }

public:	
	bool IsStore() const;
	bool FilterSearch(const QString& strSearch);
    QString GetShowName() const;
    bool GetShowCount(int &store_count, int &device_count, int &online_count);

protected:

};

class DeviceTreeNode : public TreeItem, public TreeItemData<DeviceNode>
{
public:
	explicit DeviceTreeNode(DeviceNode* pData = nullptr);
	virtual ~DeviceTreeNode();

	/// TreeItem
    QVariant data(int role, int column) const override;;
    void* Ptr() const override { return GetData(); }
	int DataType() const override { return TREE_DATA_TYPE_DEVICE; }	

public:	
    QString GetShowName() const;
    bool IsOnline() const;
	bool FilterSearch(const QString& strSearch);

};

class GroupDeviceTree
{
private:
	static GroupDeviceTree* s_pInstance;
	GroupDeviceTree();

public:
	~GroupDeviceTree();
	static GroupDeviceTree* Instance()
	{
		if ( NULL == s_pInstance ) 
		{
			s_pInstance = new GroupDeviceTree();
            Q_ASSERT( s_pInstance != NULL );
		}
		return s_pInstance;
	}
	static void DestroyInstance()
	{
		if ( s_pInstance != NULL ) 
		{
			delete s_pInstance;
			s_pInstance = NULL;
		}
	}	

	bool appendGroupNode(GroupNode& pNode);
	bool appendDeviceNode(DeviceNode& pNode);

	bool showSearch(const QString& strSearch);

	TreeItem* root() { return mRootItem; }
	
protected:
	QMap<QString, TreeItem*> mGroupItems; // 所有组列表  
    QList<TreeItem*> mStoreItems;         // 所有门店列表
	TreeItem*  mRootItem;  //父节点
};


#endif // DEVLIST_DATA_H
